﻿#pragma once


#include <QDialog>
#include <QPushButton>
#include "QListView"
#include "QStringListModel"
#include "QFileDialog"
#include "QMessageBox"
#include "QApplication"
#include "QVBoxLayout"
#include <QDesktopWidget>
#include <QLibrary>
#include <QApplication>
#include <QLabel>
#include <QComboBox>
#include "QListView"
#include "QStringListModel"
#include "QLineEdit"
#include "QSpinBox"
#include "QRadioButton"
#include <QSettings>

#include "commonfunction.h"

#include "halcon_opencv.h"

using namespace std;

#include "qt_graphics_view_image.h"
#include "qt_graphics_shape_rectangle.h"


#include <QSettings>

class FunctionBlobMatch:public QDialog
{
    Q_OBJECT
public:
    QSettings* m_qsettings;

    Mat m_image ,m_image_show;
    QString m_path_para = "prar.json";
    QString m_section   = "";

    MyQGraphicsView* m_view ;


    /*QPushButton* m_pushbutton_load_image;


    QPushButton* m_pushbutton_open_model_image;

    QPushButton* m_pushbutton_save_model_image;*/
    //QString m_model_image_path = "model.png";





    QLabel * m_qlabel_threshold_low;
    QSpinBox * m_qspinbox_threshold_low;
    QSlider* m_qslider_threshold_low;

    QLabel * m_qlabel_threshold_high;
    QSpinBox * m_qspinbox_threshold_high;
    QSlider* m_qslider_threshold_high;

    QLabel * m_qlabel_area_low;
    QSpinBox * m_qspinbox_area_low;
    
    QLabel * m_qlabel_area_high;
    QSpinBox * m_qspinbox_area_high;

    QLabel * m_qlabel_height_low;
    QSpinBox * m_qspinbox_height_low;

    QLabel * m_qlabel_height_high;
    QSpinBox * m_qspinbox_height_high;

	QLabel * m_qlabel_width_low;
	QSpinBox * m_qspinbox_width_low;

	QLabel * m_qlabel_width_high;
	QSpinBox * m_qspinbox_width_high;


	QLabel * m_qlabel_mask_column1;
	QSpinBox * m_qspinbox_mask_column1;


	QLabel * m_qlabel_mask_column2;
	QSpinBox * m_qspinbox_mask_column2;

    QLabel   * m_qlabel_closing_height;
    QSpinBox * m_qspinbox_closing_height;



    QComboBox* m_qcombobox_first_black;
    int first_black=0;

    QLabel * m_qlabel_first_black_erosion;
    QSpinBox * m_qspinbox_first_black_erosion;
    QSlider* m_qslider_first_black_erosion;


    QPushButton* m_pushbutton_create_model;

    QPushButton* m_pushbutton_show_orign_image;
    QPushButton* m_pushbutton_detection;
    QPushButton* m_pushbutton_save_parameter;
    QPushButton* m_pushbutton_return;

    QLabel* m_qlabel_message;

    int m_result;


    HDevProcedure* m_proc_createBlobMatch;
    HDevProcedureCall* m_call_createBlobMatch;

    HDevProcedure* m_proc_blobMatch;
    HDevProcedureCall* m_call_blobMatch;
    HObject hobject_out, region_out,region_erosion;
    int row1, column1, row2, column2;
    double m_model_row, m_model_column, m_model_phi, m_model_length1, m_model_length2;

public:
    explicit FunctionBlobMatch(QDialog *parent = nullptr, QSettings* qsettings = nullptr,QString section = "");
    ~FunctionBlobMatch() ;

    void         create_model();
    virtual void detectionImage();
    virtual bool detection(HObject image_in,QString& message);
    virtual void draw( Mat image_in,Mat& image_out);
    virtual void loadParameter(QString path_in,QString section);
    virtual void saveParameter();
    virtual bool showDialog();
    void         testImage();
    void value_changed_m_qspinbox_threshold_low(int value);
signals:
    void saveImage();
};
#pragma execution_character_set("utf-8")
